<?php
class Upload extends BaseController {

	
	public function __construct() {
		parent::__construct();
		$this->load->model('UploadModel');
	}

	function doUpload() {
		if (isset($_SESSION['user'])) {
			redirect('albums/editAlbums');
		} else {
			redirect('login');
		}
	}

	function uploadImage() {
		$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
		$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
		$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
		
		if ($this->UploadModel->uploadFile($_SESSION['user'],$chunk,$chunks,$fileName)) {
			if (!isset($_SESSION['uploaded'])) {
				$_SESSION['uploaded'] = array();
			}
			array_push($_SESSION['uploaded'],$fileName);
		}
	}
	
	function saveImages() {
		$album_name = $_GET['album_name'];
		if ($this->UploadModel->saveImages($_SESSION['uploaded'],$_SESSION['user'],$album_name)) {
			$_SESSION['uploaded'] = array();
			redirect('Albums/viewImages?album_name='.$album_name);
		}
	}

}